package com.shiroha.user.controller.advice;

import com.mybatisflex.core.exception.MybatisFlexException;
import com.shiroha.common.exception.ServiceException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(ServiceException.class)
    public ResponseEntity<String> handleException(ServiceException e) {
        return ResponseEntity.status(e.getErrorCode()).body(e.getMessage());
    }

    @ExceptionHandler(MybatisFlexException.class)
    public ResponseEntity<String> handleMybatisFlexException(MybatisFlexException e) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
    }
}
